package com.example.eurekaclient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * <p> Ask </p>
 *
 * @author Chris
 * @since 2022/12/9 15:58
 */
@RestController
public class AskController {

    @Value("${spring.application.name}")
    private String name;

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("/ask")
    public String ask() {
        // 从 eureka-client-service 服务提供者中请求 sayHello 服务
        return restTemplate.getForEntity("http://EUREKA-CLIENT-SERVICE/hello/{name}",
                String.class, name).getBody();
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

}